package com.fastjars.generator.plugin;

import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.PluginAdapter;

import java.util.List;

/**
 * GenReplaceMapperToDaoPlugin
 * 自定义Dao层后缀名称 UserMapper==&gt; UserDao
 * @author Brant Liu <br> 邮箱：<br>lbf1988@qq.com <br>日期：<br>2017/12/23
 * @version 1.0.0
 */
public class GenReplaceMapperToDaoPlugin extends PluginAdapter {
    private String mapperSuffix;

    private static final String defaultSuffix = "Mapper";

    @Override
    public boolean validate(List<String> list) {
        mapperSuffix = this.properties.getProperty("mapperSuffix","Dao");
        return true;
    }

    @Override
    public void initialized(IntrospectedTable introspectedTable) {
        String mapperType=introspectedTable.getMyBatis3JavaMapperType();
        introspectedTable.setMyBatis3JavaMapperType(mapperType.replaceFirst(defaultSuffix,mapperSuffix));

        String xmlMapper= introspectedTable.getMyBatis3XmlMapperFileName();
        introspectedTable.setMyBatis3XmlMapperFileName(xmlMapper.replaceFirst(defaultSuffix,mapperSuffix));
    }
}
